package sz.szsmk.citizencard.ui.activity;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.chenenyu.router.annotation.Route;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.HomeWeathActivityBinding;
import sz.szsmk.citizencard.ioc.Compontent.DaggerCommonActivityComponent;
import sz.szsmk.citizencard.model.network.bean.response.WeathDetailRes;
import sz.szsmk.citizencard.mvp.contract.IHomeWeathContact;
import sz.szsmk.citizencard.mvp.presenter.WeathPresenter;
import sz.szsmk.citizencard.ui.adapter.WeathDetailAdapter;
import sz.szsmk.citizencard.ui.base.IBaseActivity;
import sz.szsmk.citizencard.util.PubUtils;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/8/10 10:10
 * description: 天气详情
 */
@Route("weath")
public class HomeWeathActivity extends IBaseActivity<WeathPresenter, HomeWeathActivityBinding>
        implements IHomeWeathContact.IHomeWeathView {


    private RecyclerView weathRv;
    private WeathDetailAdapter detailAdapter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.home_weath_activity;
    }

    @Override
    protected void initInjector() {
        DaggerCommonActivityComponent.builder().appCompontent(DaggerApplication.getAppComponent())
                .build().inject(this);
    }

    @Override
    protected void initViews() {
        weathRv = (RecyclerView) findViewById(R.id.weath_rv);
        dataBinding.titleLayout.settingTitle.setText("天气");
        dataBinding.titleLayout.back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        weathRv.setLayoutManager(linearLayoutManager);
        detailAdapter = new WeathDetailAdapter(this);
        weathRv.setAdapter(detailAdapter);
        weathRv.post(new Runnable() {
            @Override
            public void run() {
                showLoadingDialog();
                mPresenter.getWeathFore();
            }
        });
    }

    @Override
    protected void updateViews() {

    }

    @Override
    public void getWeathForeError(String response) {
        dismissLoadingDialog();
        PubUtils.popTipOrWarn(this,response);
    }

    @Override
    public void delWeathForeSuccess(WeathDetailRes response) {
        dismissLoadingDialog();
        detailAdapter.setResponse(response);
        detailAdapter.notifyDataSetChanged();
    }
}
